package adt;

public class Queue {

	private int maxsize;
	private int front;
	private int rear;
	private int nItems;
	private Object[] elements;

	public Queue(int s) {
		maxsize = s;
		front = 0;
		rear = -1;
		nItems = 0;
		elements = new Object[maxsize];
	}

	public void enqueue(Object x) {
		if (rear == maxsize - 1)
			rear = -1;

		elements[++rear] = x;
		nItems++;
	}

	public Object dequeue() {
		Object result = elements[front];
		front++;

		if (front == maxsize)
			front = 0;

		nItems--;
		return result;
	}

	public Object peek() {
		return elements[front];
	}

	public boolean isEmpty() {
		return (nItems == 0);
	}

	public boolean isFull() {
		return (nItems == maxsize);
	}

	public int size() {
		return nItems;
	}
}